<?php

class DB
{
  private static $instance = NULL;
  private $dbHost;
  private $dbUser;
  private $dbPassword;
  private $dbDatabase;

//*****************************************************************************
  	
//Constructor: - connects to the MySQL server
private function __construct()
{
  global $config;
  $this->dbHost = "localhost";
  $this->dbUser = "root";
  $this->dbPassword = "";
  $this->dbDatabase = "patientenmanagement";

  //connect to DB
  mysql_connect($this->dbHost, $this->dbUser, $this->dbPassword) or die("No connection to MySQL server: " . mysql_error());
}
		
//*****************************************************************************

//getInstance:
//  - returns the instance of the Db object
//  - Db is s singleton, there is only one instance
public static function getInstance()
{
  if (self::$instance === NULL)
  {
    self::$instance = new Db();
  }
  return self::$instance;
}
		
//*****************************************************************************

//selectDB:
//  - selects the given DB
public function selectDB()
{
  mysql_select_db($this->dbDatabase);
}

//*****************************************************************************
//****** DATABASE ACCESS FUNCTIONS ********************************************
//*****************************************************************************


function getPatientenValues()
{
	$resultArray = array();

	DB::getInstance()->selectDB("patientenmanagement");
	$insertExpStr = "SELECT patientID, patientVorname, patientNachname, patientStrasse, patientPLZ, patientOrt FROM patient ORDER BY patientNachname;";
	$selectPatient = mysql_query($insertExpStr) or die("getPatientenValues: Request for getPatientenValues failed: " . mysql_error());
	while ($line = mysql_fetch_assoc($selectPatient))
	{
		$tmpArray = array($line['patientID'], $line['patientVorname'], $line['patientNachname'], $line['patientStrasse'], $line['patientStrasse'], $line['patientPLZ'], $line['patientOrt'] );
		array_push($resultArray, $tmpArray);
	}
	return $resultArray;
}

function getPatientWithID($patientID){
	
	DB::getInstance()->selectDB("patientenmanagement");
	$insertExpStr = "SELECT patientVorname, patientNachname, patientStrasse, patientPLZ, patientOrt, patientTelefonPrivat, patientTelefonArbeit, patientTelefonMobil, patientTelefonFax, patientEmail, patientGeburtsdatum, patientNotizen FROM patient WHERE patientID='" . $patientID . "';";
	$selectPatient = mysql_query($insertExpStr) or die("getPatientWithID: Request for getPatientWithID failed: " . mysql_error());
	while ($line = mysql_fetch_assoc($selectPatient))
	{
		$patient['patientVorname'] = $line['patientVorname'];
		$patient['patientNachname'] = $line['patientNachname'];
		$patient['patientStrasse'] = $line['patientStrasse'];
		$patient['patientPLZ'] = $line['patientPLZ']; 
		$patient['patientOrt'] =  $line['patientOrt'];
		$patient['patientTelefonPrivat'] =  $line['patientTelefonPrivat'];
		$patient['patientTelefonArbeit'] =  $line['patientTelefonArbeit'];
		$patient['patientTelefonMobil'] =  $line['patientTelefonMobil'];
		$patient['patientTelefonFax'] =  $line['patientTelefonFax'];
		$patient['patientEmail'] =  $line['patientEmail'];
		$patient['patientGeburtsdatum'] =  $line['patientGeburtsdatum'];
		$patient['patientNotizen'] =  $line['patientNotizen'];
	}
	return $patient;
}

}
?>